<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
date_default_timezone_set('Asia/Ho_Chi_Minh');
function is_admin(){
    $CI =& get_instance();
    if(isset($CI->session->userdata['rule'])) {
        if($CI->session->userdata['rule']=='1') return true;
        else return false;
    }else {
        return false;
    }
}
function is_login(){
    $CI =& get_instance();
    if(isset($CI->session->userdata['id'])) {
         return true;
    }else {
        return false;
    }
}
function auth_name(){
     $CI =& get_instance();
     if(isset($CI->session->userdata['name'])) return $CI->session->userdata['name'];
     else return '';
}
function auth_id(){
     $CI =& get_instance();
     if(isset($CI->session->userdata['id'])) return $CI->session->userdata['id'];
     else return '';
}
function routing_admin(){
     if(is_admin()){
        redirect(base_url().'projects');
     }else {
        redirect(base_url().'works/my_works');
     }
}
function is_pm($pj_id){
    $CI =& get_instance();
    if(isset($CI->session->userdata['id'])) {
        $pn_id = $CI->session->userdata['id'];
        $CI->load->model('personnel_model');
        $role = $CI->personnel_model->get_role($pn_id,$pj_id);
        if($role==1){
            return true;
        }else {
            return false;
        }
    }else {
        return false;
    }
}
function is_boss($pj_id){
    $CI =& get_instance();
    if(isset($CI->session->userdata['id'])) {
        $pn_id = $CI->session->userdata['id'];
        $CI->load->model('personnel_model');
        $role = $CI->personnel_model->get_role($pn_id,$pj_id);
        if($role==null) return false;
        if($role==2) return true;
        return false;
    }else {
        return false;
    }
}
function is_member($pj_id){
    $CI =& get_instance();
    if(isset($CI->session->userdata['id'])) {
        $pn_id = $CI->session->userdata['id'];
        $CI->load->model('personnel_model');
        $role = $CI->personnel_model->get_role($pn_id,$pj_id);
        if($role==null) return false;
        if($role==3) return true;
        return false;
    }else {
        return false;
    }
}
?>